<template>
  <div class="mooc-ai-page">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="container">
        <div class="header-content">
          <div class="header-info">
            <h1 class="page-title">AI学习助手</h1>
            <p class="page-subtitle">智能编程助手，为您提供个性化学习指导</p>
          </div>
          <div class="ai-status">
            <div class="status-indicator" :class="{ online: isAiOnline }">
              <div class="status-dot"></div>
              <span class="status-text">{{ isAiOnline ? 'AI助手在线' : 'AI助手离线' }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 未登录提示 -->
    <div v-if="!isLoggedIn" class="login-prompt">
      <div class="container">
        <div class="prompt-card">
          <div class="prompt-icon">
            <svg width="80" height="80" viewBox="0 0 24 24" fill="none" stroke="currentColor">
              <path d="M9 12l2 2 4-4"></path>
              <path d="M21 12c0 1.2-.4 2.3-1 3.2a10 10 0 01-1.7 2.8"></path>
              <path d="M3 12c0-1.2.4-2.3 1-3.2a10 10 0 011.7-2.8"></path>
              <circle cx="12" cy="12" r="10"></circle>
            </svg>
          </div>
          <h2 class="prompt-title">欢迎使用AI学习助手</h2>
          <p class="prompt-subtitle">登录后即可享受个性化的AI编程指导服务</p>
          <div class="prompt-features">
            <div class="feature-item">
              <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                <polyline points="22,12 18,12 15,21 9,3 6,12 2,12"></polyline>
              </svg>
              <span>智能代码分析</span>
            </div>
            <div class="feature-item">
              <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                <path d="M9 11a3 3 0 1 1 6 0a3 3 0 0 1-6 0"></path>
                <path d="M17.5 12.5a9 9 0 1 1-11 0"></path>
                <path d="M12 3v3"></path>
              </svg>
              <span>学习路径推荐</span>
            </div>
            <div class="feature-item">
              <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                <circle cx="12" cy="12" r="10"></circle>
                <path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path>
                <line x1="12" y1="17" x2="12.01" y2="17"></line>
              </svg>
              <span>24/7问题解答</span>
            </div>
          </div>
          <div class="prompt-actions">
            <button class="primary-btn" @click="$router.push('/login')">立即登录</button>
            <button class="secondary-btn" @click="$router.push('/register')">注册账号</button>
          </div>
        </div>
      </div>
    </div>

    <!-- AI助手界面 -->
    <div v-else class="ai-interface">
      <div class="container">
        <!-- 使用统一的AI助手组件 -->
        <AIAssistant 
          :userId="authStore.user?.id || 0" 
          :courseId="undefined"
          :fullscreen="true"
        />
        
        <!-- 保留原有布局作为备用 -->
        <div class="ai-layout" style="display: none;">
          <!-- 侧边栏 -->
          <div class="ai-sidebar">
            <div class="sidebar-section">
              <h3 class="section-title">快速操作</h3>
              <div class="quick-actions">
                <button class="action-btn" @click="startNewChat">
                  <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                    <line x1="12" y1="5" x2="12" y2="19"></line>
                    <line x1="5" y1="12" x2="19" y2="12"></line>
                  </svg>
                  新对话
                </button>
                <button class="action-btn" @click="showCodeReview">
                  <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                    <polyline points="16,18 22,12 16,6"></polyline>
                    <polyline points="8,6 2,12 8,18"></polyline>
                  </svg>
                  代码审查
                </button>
                <button class="action-btn" @click="showLearningPlan">
                  <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                    <path d="M22 10v6M2 10l10-5 10 5-10 5z"></path>
                    <path d="M6 12v5c3 3 9 3 12 0v-5"></path>
                  </svg>
                  学习计划
                </button>
              </div>
            </div>

            <div class="sidebar-section">
              <h3 class="section-title">对话历史</h3>
              <div class="chat-history">
                <div 
                  v-for="chat in chatHistory" 
                  :key="chat.id"
                  class="history-item"
                  :class="{ active: currentChatId === chat.id }"
                  @click="loadChat(chat.id)"
                >
                  <div class="history-title">{{ chat.title }}</div>
                  <div class="history-time">{{ formatTime(chat.updatedAt) }}</div>
                </div>
              </div>
            </div>
          </div>

          <!-- 主聊天区域 -->
          <div class="ai-main">
            <div class="chat-container">
              <!-- 聊天头部 -->
              <div class="chat-header">
                <div class="assistant-info">
                  <div class="assistant-avatar">
                    <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                      <path d="M9 12l2 2 4-4"></path>
                      <path d="M21 12c0 1.2-.4 2.3-1 3.2a10 10 0 01-1.7 2.8"></path>
                      <path d="M3 12c0-1.2.4-2.3 1-3.2a10 10 0 011.7-2.8"></path>
                      <circle cx="12" cy="12" r="10"></circle>
                    </svg>
                  </div>
                  <div class="assistant-details">
                    <h3 class="assistant-name">启航编程助手</h3>
                    <p class="assistant-desc">专业的编程学习指导</p>
                  </div>
                </div>
                <div class="chat-actions">
                  <button class="action-btn" @click="clearChat" title="清空对话">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                      <polyline points="3,6 5,6 21,6"></polyline>
                      <path d="M19,6v14a2,2,0,0,1-2,2H7a2,2,0,0,1-2-2V6m3,0V4a2,2,0,0,1,2-2h4a2,2,0,0,1,2,2V6"></path>
                    </svg>
                  </button>
                </div>
              </div>

              <!-- 聊天消息 -->
              <div class="chat-messages" ref="messagesContainer">
                <div v-if="messages.length === 0" class="welcome-message">
                  <div class="welcome-icon">
                    <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                      <path d="M9 12l2 2 4-4"></path>
                      <path d="M21 12c0 1.2-.4 2.3-1 3.2a10 10 0 01-1.7 2.8"></path>
                      <path d="M3 12c0-1.2.4-2.3 1-3.2a10 10 0 011.7-2.8"></path>
                      <circle cx="12" cy="12" r="10"></circle>
                    </svg>
                  </div>
                  <h3>欢迎使用启航编程助手</h3>
                  <p>我可以帮助您：</p>
                  <div class="welcome-suggestions">
                    <button class="suggestion-btn" @click="sendSuggestion('解释JavaScript闭包概念')">
                      解释JavaScript闭包概念
                    </button>
                    <button class="suggestion-btn" @click="sendSuggestion('推荐Python学习路径')">
                      推荐Python学习路径
                    </button>
                    <button class="suggestion-btn" @click="sendSuggestion('帮我分析这段代码')">
                      帮我分析这段代码
                    </button>
                    <button class="suggestion-btn" @click="sendSuggestion('解决编程问题')">
                      解决编程问题
                    </button>
                  </div>
                </div>

                <div 
                  v-for="message in messages" 
                  :key="message.id"
                  class="message"
                  :class="{ user: message.type === 'user', assistant: message.type === 'assistant' }"
                >
                  <div class="message-avatar">
                    <div v-if="message.type === 'user'" class="user-avatar">
                      <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                        <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                        <circle cx="12" cy="7" r="4"></circle>
                      </svg>
                    </div>
                    <div v-else class="ai-avatar">
                      <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                        <path d="M9 12l2 2 4-4"></path>
                        <path d="M21 12c0 1.2-.4 2.3-1 3.2a10 10 0 01-1.7 2.8"></path>
                        <path d="M3 12c0-1.2.4-2.3 1-3.2a10 10 0 011.7-2.8"></path>
                        <circle cx="12" cy="12" r="10"></circle>
                      </svg>
                    </div>
                  </div>
                  <div class="message-content">
                    <div class="message-bubble">
                      <div v-if="message.type === 'assistant' && message.isTyping" class="typing-indicator">
                        <span></span>
                        <span></span>
                        <span></span>
                      </div>
                      <div v-else class="message-text" v-html="formatMessage(message.content)"></div>
                    </div>
                    <div class="message-time">{{ formatTime(message.timestamp) }}</div>
                  </div>
                </div>
              </div>

              <!-- 输入区域 -->
              <div class="chat-input">
                <div class="input-container">
                  <div class="input-wrapper">
                    <textarea 
                      v-model="inputMessage"
                      placeholder="输入您的问题，比如：如何学习React？"
                      class="message-input"
                      rows="1"
                      @keydown="handleKeyDown"
                      @input="autoResize"
                      ref="messageInput"
                    ></textarea>
                    <div class="input-actions">
                      <button class="attach-btn" @click="showFileUpload" title="上传文件">
                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                          <path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"></path>
                        </svg>
                      </button>
                      <button 
                        class="send-btn" 
                        :disabled="!inputMessage.trim() || isLoading"
                        @click="sendMessage"
                      >
                        <svg v-if="!isLoading" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                          <line x1="22" y1="2" x2="11" y2="13"></line>
                          <polygon points="22,2 15,22 11,13 2,9 22,2"></polygon>
                        </svg>
                        <svg v-else class="loading-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                          <path d="M21 12a9 9 0 1 1-6.219-8.56"/>
                        </svg>
                      </button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed, onMounted, nextTick } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { ElMessage } from 'element-plus'
import AIAssistant from '@/components/AIAssistant.vue'

const router = useRouter()
const authStore = useAuthStore()

// 状态
const isAiOnline = ref(true)
const isLoading = ref(false)
const inputMessage = ref('')
const currentChatId = ref<string | null>(null)
const messagesContainer = ref<HTMLElement>()
const messageInput = ref<HTMLTextAreaElement>()

// 数据
const messages = ref<Array<{
  id: string
  type: 'user' | 'assistant'
  content: string
  timestamp: string
  isTyping?: boolean
}>>([])

const chatHistory = ref<Array<{
  id: string
  title: string
  updatedAt: string
}>>([
  {
    id: '1',
    title: 'JavaScript基础学习',
    updatedAt: '2024-01-15T10:30:00Z'
  },
  {
    id: '2',
    title: 'React项目实战问题',
    updatedAt: '2024-01-14T16:45:00Z'
  },
  {
    id: '3',
    title: 'Python数据结构',
    updatedAt: '2024-01-13T09:20:00Z'
  }
])

// 计算属性
const isLoggedIn = computed(() => authStore.isLoggedIn && authStore.user?.id)

// 方法
const startNewChat = () => {
  currentChatId.value = null
  messages.value = []
  inputMessage.value = ''
}

const showCodeReview = () => {
  inputMessage.value = '请帮我审查以下代码：\n```javascript\n// 在这里粘贴您的代码\n```'
  nextTick(() => {
    messageInput.value?.focus()
  })
}

const showLearningPlan = () => {
  inputMessage.value = '请为我制定一个编程学习计划'
  nextTick(() => {
    messageInput.value?.focus()
  })
}

const loadChat = (chatId: string) => {
  currentChatId.value = chatId
  // TODO: 加载聊天历史
  console.log('加载聊天:', chatId)
}

const clearChat = () => {
  messages.value = []
}

const sendSuggestion = (suggestion: string) => {
  inputMessage.value = suggestion
  sendMessage()
}

const sendMessage = async () => {
  if (!inputMessage.value.trim() || isLoading.value) return

  const userMessage = {
    id: Date.now().toString(),
    type: 'user' as const,
    content: inputMessage.value,
    timestamp: new Date().toISOString()
  }

  messages.value.push(userMessage)
  
  const userInput = inputMessage.value
  inputMessage.value = ''
  
  // 添加AI正在输入的消息
  const typingMessage = {
    id: (Date.now() + 1).toString(),
    type: 'assistant' as const,
    content: '',
    timestamp: new Date().toISOString(),
    isTyping: true
  }
  
  messages.value.push(typingMessage)
  
  isLoading.value = true
  
  try {
    // 模拟AI响应
    await new Promise(resolve => setTimeout(resolve, 1500))
    
    // 移除输入提示
    const typingIndex = messages.value.findIndex(m => m.isTyping)
    if (typingIndex > -1) {
      messages.value.splice(typingIndex, 1)
    }
    
    // 添加AI响应
    const aiResponse = {
      id: (Date.now() + 2).toString(),
      type: 'assistant' as const,
      content: generateAIResponse(userInput),
      timestamp: new Date().toISOString()
    }
    
    messages.value.push(aiResponse)
    
    // 滚动到底部
    nextTick(() => {
      scrollToBottom()
    })
    
  } catch (error) {
    ElMessage.error('发送消息失败，请重试')
    // 移除输入提示
    const typingIndex = messages.value.findIndex(m => m.isTyping)
    if (typingIndex > -1) {
      messages.value.splice(typingIndex, 1)
    }
  } finally {
    isLoading.value = false
  }
  
  // 滚动到底部
  nextTick(() => {
    scrollToBottom()
  })
}

const generateAIResponse = (userInput: string): string => {
  // 简单的模拟AI响应
  const lowerInput = userInput.toLowerCase()
  
  if (lowerInput.includes('javascript') || lowerInput.includes('js')) {
    return `关于JavaScript的问题，我来为您详细解答：

JavaScript是一种动态的、弱类型的编程语言，主要用于Web开发。以下是一些关键概念：

**基础概念：**
- 变量声明：\`let\`, \`const\`, \`var\`
- 数据类型：String, Number, Boolean, Object, Array等
- 函数：function声明和箭头函数

**进阶概念：**
- 闭包(Closure)：函数能够访问其词法作用域外的变量
- 原型链：JavaScript对象继承的基础
- 异步编程：Promise, async/await

需要我详细解释其中某个概念吗？`
  }
  
  if (lowerInput.includes('python')) {
    return `Python是一门优秀的编程语言，特别适合初学者：

**Python的优势：**
- 语法简洁易懂
- 强大的生态系统
- 广泛的应用领域

**学习路径推荐：**
1. **基础语法** (2-3周)
   - 变量、数据类型
   - 控制流程（if/for/while）
   - 函数定义

2. **面向对象** (1-2周)
   - 类和对象
   - 继承和多态

3. **项目实践** (持续)
   - Web开发 (Django/Flask)
   - 数据分析 (Pandas/NumPy)
   - 机器学习 (Scikit-learn)

您想深入了解哪个方面？`
  }
  
  if (lowerInput.includes('react')) {
    return `React是目前最流行的前端框架之一，让我为您介绍：

**React核心概念：**
- **组件(Component)**: 可复用的UI单元
- **JSX**: JavaScript和HTML的结合语法
- **Props**: 组件间数据传递
- **State**: 组件内部状态管理
- **生命周期**: 组件的创建、更新、销毁过程

**学习建议：**
1. 先掌握JavaScript ES6+语法
2. 理解组件化思想
3. 练习Props和State使用
4. 学习React Hooks
5. 实际项目练习

**推荐学习资源：**
- React官方文档
- 创建小型Todo应用
- 学习React Router处理路由

需要我详细解释某个概念或提供代码示例吗？`
  }
  
  // 默认响应
  return `感谢您的提问！作为启航编程助手，我可以帮助您：

🔧 **代码问题解答**
- 调试代码错误
- 解释编程概念
- 代码优化建议

📚 **学习指导**
- 制定学习计划
- 推荐学习资源
- 技术栈选择建议

💡 **项目协助**
- 架构设计思路
- 最佳实践分享
- 技术选型建议

请告诉我您具体遇到的问题，我会为您提供详细的解答！`
}

const handleKeyDown = (event: KeyboardEvent) => {
  if (event.key === 'Enter' && !event.shiftKey) {
    event.preventDefault()
    sendMessage()
  }
}

const autoResize = () => {
  const textarea = messageInput.value
  if (textarea) {
    textarea.style.height = 'auto'
    textarea.style.height = textarea.scrollHeight + 'px'
  }
}

const showFileUpload = () => {
  // TODO: 实现文件上传功能
  ElMessage.info('文件上传功能开发中...')
}

const scrollToBottom = () => {
  if (messagesContainer.value) {
    messagesContainer.value.scrollTop = messagesContainer.value.scrollHeight
  }
}

const formatMessage = (content: string) => {
  // 简单的markdown格式化
  return content
    .replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
    .replace(/\*(.*?)\*/g, '<em>$1</em>')
    .replace(/`(.*?)`/g, '<code>$1</code>')
    .replace(/```([\s\S]*?)```/g, '<pre><code>$1</code></pre>')
    .replace(/\n/g, '<br>')
}

const formatTime = (time: string) => {
  const date = new Date(time)
  const now = new Date()
  const diff = now.getTime() - date.getTime()
  
  const minutes = Math.floor(diff / 60000)
  const hours = Math.floor(diff / 3600000)
  const days = Math.floor(diff / 86400000)
  
  if (days > 0) {
    return `${days}天前`
  } else if (hours > 0) {
    return `${hours}小时前`
  } else if (minutes > 0) {
    return `${minutes}分钟前`
  } else {
    return '刚刚'
  }
}

// 生命周期
onMounted(() => {
  authStore.initAuth()
})
</script>

<style scoped>
/* My MOOC风格的AI助手页面 */
.mooc-ai-page {
  min-height: 100vh;
  background: #f8f9fa;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 页面头部 */
.page-header {
  background: white;
  border-bottom: 1px solid #e5e5e5;
  padding: 30px 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-info {
  flex: 1;
}

.page-title {
  font-size: 28px;
  font-weight: 400;
  color: #333;
  margin-bottom: 8px;
}

.page-subtitle {
  font-size: 16px;
  color: #666;
  margin: 0;
}

.ai-status {
  display: flex;
  align-items: center;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  background: #f8f9fa;
  color: #666;
}

.status-indicator.online {
  background: #e8f5e8;
  color: #52c41a;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #999;
  animation: pulse 2s infinite;
}

.status-indicator.online .status-dot {
  background: #52c41a;
}

/* 未登录提示 */
.login-prompt {
  padding: 80px 0;
}

.prompt-card {
  background: white;
  border-radius: 16px;
  padding: 60px 40px;
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

.prompt-icon {
  color: #4A90E2;
  margin-bottom: 24px;
}

.prompt-title {
  font-size: 28px;
  font-weight: 500;
  color: #333;
  margin-bottom: 12px;
}

.prompt-subtitle {
  font-size: 16px;
  color: #666;
  margin-bottom: 40px;
}

.prompt-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #666;
}

.feature-item svg {
  color: #4A90E2;
}

.prompt-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.primary-btn,
.secondary-btn {
  padding: 12px 24px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.primary-btn {
  background: #4A90E2;
  color: white;
}

.primary-btn:hover {
  background: #357ABD;
}

.secondary-btn {
  background: #f8f9fa;
  color: #333;
  border: 1px solid #ddd;
}

.secondary-btn:hover {
  background: #e9ecef;
}

/* AI界面 */
.ai-interface {
  padding: 30px 0;
}

.ai-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  height: calc(100vh - 200px);
}

/* 侧边栏 */
.ai-sidebar {
  background: white;
  border-radius: 8px;
  padding: 24px;
  border: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-section {
  flex-shrink: 0;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
}

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-btn {
  background: none;
  border: 1px solid #e5e5e5;
  color: #333;
  padding: 12px 16px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  transition: all 0.2s;
  text-align: left;
}

.action-btn:hover {
  border-color: #4A90E2;
  color: #4A90E2;
  background: #f8f9fa;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  padding: 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.history-item:hover {
  background: #f8f9fa;
}

.history-item.active {
  background: #e8f4fd;
  border-color: #4A90E2;
}

.history-title {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-bottom: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-time {
  font-size: 12px;
  color: #999;
}

/* 主聊天区域 */
.ai-main {
  background: white;
  border-radius: 8px;
  border: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e5e5e5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.assistant-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.assistant-avatar {
  width: 48px;
  height: 48px;
  background: #4A90E2;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.assistant-details {
  flex: 1;
}

.assistant-name {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
}

.assistant-desc {
  font-size: 14px;
  color: #666;
  margin: 0;
}

.chat-actions {
  display: flex;
  gap: 8px;
}

/* 聊天消息 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.welcome-message {
  text-align: center;
  padding: 40px 20px;
}

.welcome-icon {
  color: #4A90E2;
  margin-bottom: 24px;
}

.welcome-message h3 {
  font-size: 20px;
  font-weight: 500;
  color: #333;
  margin-bottom: 12px;
}

.welcome-message p {
  color: #666;
  margin-bottom: 32px;
}

.welcome-suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  max-width: 600px;
  margin: 0 auto;
}

.suggestion-btn {
  background: #f8f9fa;
  border: 1px solid #e5e5e5;
  color: #333;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  text-align: left;
}

.suggestion-btn:hover {
  border-color: #4A90E2;
  background: #e8f4fd;
  color: #4A90E2;
}

.message {
  display: flex;
  gap: 12px;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  flex-shrink: 0;
}

.user-avatar,
.ai-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.user-avatar {
  background: #666;
}

.ai-avatar {
  background: #4A90E2;
}

.message-content {
  flex: 1;
  max-width: 70%;
}

.message.user .message-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-bubble {
  background: #f8f9fa;
  padding: 12px 16px;
  border-radius: 16px;
  margin-bottom: 4px;
}

.message.user .message-bubble {
  background: #4A90E2;
  color: white;
}

.message-text {
  line-height: 1.5;
  word-wrap: break-word;
}

.message-time {
  font-size: 12px;
  color: #999;
  padding: 0 4px;
}

/* 输入提示动画 */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
  animation: typing 1.5s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

/* 输入区域 */
.chat-input {
  padding: 20px 24px;
  border-top: 1px solid #e5e5e5;
  flex-shrink: 0;
}

.input-container {
  max-width: 100%;
}

.input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: #f8f9fa;
  border-radius: 24px;
  padding: 12px 16px;
  border: 1px solid #e5e5e5;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: #4A90E2;
  background: white;
}

.message-input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.5;
  max-height: 120px;
  min-height: 20px;
  font-family: inherit;
}

.input-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.attach-btn,
.send-btn {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.attach-btn:hover {
  background: #e5e5e5;
  color: #4A90E2;
}

.send-btn {
  background: #4A90E2;
  color: white;
}

.send-btn:hover:not(:disabled) {
  background: #357ABD;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.loading-icon {
  animation: spin 1s linear infinite;
}

/* 动画 */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .ai-layout {
    grid-template-columns: 250px 1fr;
  }
}

@media (max-width: 768px) {
  .ai-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  
  .ai-sidebar {
    order: 2;
    height: auto;
  }
  
  .ai-main {
    order: 1;
    height: 70vh;
  }
  
  .prompt-card {
    padding: 40px 20px;
  }
  
  .prompt-features {
    grid-template-columns: 1fr;
  }
  
  .prompt-actions {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .page-title {
    font-size: 24px;
  }
  
  .header-content {
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
  }
  
  .welcome-suggestions {
    grid-template-columns: 1fr;
  }
  
  .message-content {
    max-width: 85%;
  }
}

/* 代码样式 */
:deep(code) {
  background: #f6f8fa;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9em;
}

:deep(pre) {
  background: #f6f8fa;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

:deep(pre code) {
  background: none;
  padding: 0;
}

:deep(strong) {
  font-weight: 600;
}
</style>